var Window = cc.Class.extend({
	scene: null,
	layer: null,
	flow: null,
	step: 1,
	tag: null,
	rootNode:null,
	closeButton: null,
	ctor:function (parent, flow, tag) {
		this.tag = tag;
		this.flow = flow;
		this.layer = parent;
		this.scene = parent.getParent();
		this.init();
	},
	init:function (){
		this.rootNode = new cc.NodeGrid();
		this.rootNode.setScale(0.1);
		this.rootNode.setRotation(180);
		this.layer.addChild(this.rootNode, 99, this.tag);
		
		this.bg = new cc.Sprite("#window/lite.png");
		this.bg.setPosition(gg.c_width,gg.c_height);
		this.rootNode.addChild(this.bg, 1);
		
		this.initSp();
	},
	initSp:function (){
		// 初始化，自定义元素
	},
	open:function(){
		var scale = cc.scaleTo(0.5,1);
		var rotate = cc.rotateTo(0.5,0);
		var spawn = cc.spawn(scale,rotate);
		var sequence = cc.sequence(spawn);
		this.rootNode.runAction(sequence);
	},
	close:function(){
		var func = cc.callFunc(this.destroy, this);
		var scale = cc.scaleTo(0.5,0.1);
		var rotate = cc.rotateTo(0.5,180);
		var spawn = cc.spawn(scale, rotate);
		var sequence = cc.sequence(cc.delayTime(0.2),spawn,func);
		this.rootNode.runAction(sequence);
	},
	destroy:function() {
		synch_listener = true;
	},
	byTag:function(tag){
		return this.menu.getChildByTag(tag);
	},
	eventMenuCallback:function(pSender){
		this.showDesc(pSender.getTag());
		if(!synch_listener){
			return;
		} else {
			synch_listener = false;
		}
		if(cur_tool != TAG_BUTTON_HAND){
			// 描述
			return;
		}
		if(!this.flow.checkTag(pSender.getTag())){
			// 是否可以触发
			synch_listener = true;
			_.error();
			return;
		} else {
			_.clever();
		}
		this.step ++;
		if(this.flow.flow.incast == TAG_WINDOW_CLOSE){
			this.closeWin();
		}
		this.callbackSp(pSender);
	},
	showDesc:function(tag){
		if(cur_tool == TAG_BUTTON_HELP){
			for(var i = 0; i< sprite_json.length; i++){
				if(sprite_json[i].tag == tag){
					this.scene.tip_layer.sayFlash(sprite_json[i].desc);
					cc.log(sprite_json[i].desc);
					break;
				}
			}
		}
	},
	callback:function(pSender){
		if(!synch_listener){
			return;
		} else {
			synch_listener = false;
		}
		if(this.flow.checkTag(pSender.getTag())){
			this.step = 1;
			this.flow.next();
		} 
		this.close();
	},
	callbackSp:function(){
		// 重写
	},
	closeWin:function(){
		this.step = 1;
		this.layer.scheduleOnce(this.close.bind(this),2);
	}
})